#coding:utf-8
'''
create on 2017-09-01
@author:sandy
'''

from pycommon import TBaseFactory
import time
import Client

class ClientFactory(TBaseFactory.TBaseFactory):

    def __init__(self):
        TBaseFactory.TBaseFactory.__init__(self)
    
    def createClient(self,pid, addr):
        return Client.ClientSrv(pid,addr)

    def checkClients(self, clients):
        curtime = time.time()
        for c in clients:
            c.sendKeepAlive()
            if c.getState() == Client.CLIENT_STATE_TO_CLOSE and curtime - c.toclosetime > 10:
                c.abort()
            elif curtime - c.getLastActiveTime() > 60:
                c.abort()    

    def removeProtocol(self, prot):
        TBaseFactory.TBaseFactory.removeProtocol(self, prot)


instance = ClientFactory()

if __name__ == "__main__":
    pass